# P43 Mini design case
import numpy as np
import matplotlib.pyplot as plt

# Constants
c = 3.0e+8  # Speed of light
k_db = 10 * np.log10(1.38e-23)  # Boltzmann constant in dB
omega = (360.0 / 57.296) * (10.0 / 57.296)  # Search volume in steradians
omega_db = 10.0 * np.log10(omega)  # Convert Omega to dB
factor = 10 * np.log10(4 * np.pi)  # Factor for 4*pi in dB

# Given values
snr = 15.0  # Sensitivity SNR in dB
tsc = 2.0  # Antenna scan time in seconds
sigma_tgtm = -10  # Missile RCS in dBsm
sigma_tgta = 6  # Aircraft RCS in dBsm
te = 290.0  # Effective noise temperature in Kelvins
nf = 8  # Noise figure in dB
loss = 10.0  # Radar losses in dB

# Convert given values to dB
te_db = 10 * np.log10(te)
tsc_db = 10 * np.log10(tsc)

# Initialize arrays
var = np.arange(2, 91, 1)  # Range from 2Km to 90 Km
papm = np.zeros(len(var))
papa = np.zeros(len(var))

R0 = 10 * np.log10(60E3)
PAP0_m = snr - sigma_tgtm - tsc_db + factor + 4.0 * R0 + k_db + te_db + nf + loss + omega_db
print(f'PAP0_m: {PAP0_m}; ???')
print(f'0: {snr};')
print(f'1: {sigma_tgtm};')
print(f'2: {tsc_db};')
print(f'3: {factor};')
print(f'4: {4.0 * R0};')
print(f'5: {k_db};')
print(f'6: {te_db};')
print(f'7: {nf};')
print(f'8: {loss};')
print(f'9: {omega_db};')

# Compute Power Aperture Product (PAP) for Missile and Aircraft
for index, rangevar in enumerate(var):
    rangedb = 10 * np.log10(rangevar * 1000.0)
    papm[index] = snr - sigma_tgtm - tsc_db + factor + 4.0 * rangedb + k_db + te_db + nf + loss + omega_db
    papa[index] = snr - sigma_tgta - tsc_db + factor + 4.0 * rangedb + k_db + te_db + nf + loss + omega_db

# Plotting
plt.figure(1)
plt.plot(var, papm, 'k', label='Missile')
plt.plot(var, papa, 'k-.', label='Aircraft')
plt.xlabel('Range - Km')
plt.ylabel('Power Aperture Product - dB')
plt.legend()
plt.grid(True)
plt.show()
